package com.sparrow.common.attr.domain;

import java.util.ArrayList;
import java.util.List;

/**
 * 树结构节点，代表一个属性分类
 */
public class AttrModule {
    public final AttrModule parent;
    public final String name;
    public final List<AttrModule> children = new ArrayList<>();
    public int index;          // 用于父子关系判定
    public int subtreeIndexMax;  // 整颗子树最大index

    public AttrModule(String name) {
        this(null, name);
    }

    public AttrModule(AttrModule parent, String name) {
        this.parent = parent;
        this.name = name;
        if (this.parent != null) {
            this.parent.addChild(this);
        }
    }

    public void addChild(AttrModule child) {
        children.add(child);
    }

    public AttrModule getParent() {
        return parent;
    }

    @Override
    public String toString() {
        return "Node{" + "name='" + name + '\'' + ", index=" + index + ", childIndexMax=" + subtreeIndexMax + '}';
    }
}
